    $.nowpage = 1;
    $.limit = 40;
    var size = [],
      sex = [],
      classifyValue = [],
      type = [],
      season = [],
      color = [],
      inspiration = [],
      goodsList = [],
      filters = ["尺码", "性别", "类型", "季节", "颜色", "灵感"],
      filterArr = [],
      total = 0,
      sort = 1,

      startIndex = ($.limit * ($.nowpage - 1) + 1),
      endIndex = ($.limit * ($.nowpage));

    // url的参数
    if (GetQueryString("classify")) {
      var urlClassify = GetQueryString("classify"),
        urlclassifyValue = GetQueryString("classifyValue");
      if (urlClassify == null || urlclassifyValue == null) {
        // url无参数
        console.log("无参数")
      }
    }
    // url中的性别
    if (GetQueryString("gsex") != undefined) {
      var gsex = GetQueryString("gsex");
      if (gsex == 0) {
        $(".selected-page").html("男鞋")
      } else if (gsex == 1) {
        $(".selected-page").html("女鞋")
      } else {
        $(".selected-page").html("列表")
      }
    } else {
      $(".selected-page").html("列表")
    }

    // url的关键词
    var good = GetQueryString("search")
    // 先调用筛选数据的
    requestFilter()

    // 图片懒加载
    function lazyloadImg() {
      $("img.lazy").lazyload({
        placeholder : "", //用图片提前占位
        effect: "fadeIn"
      });
    }

    $(function () {
      lazyloadImg()
      // 鼠标滑过图片
      $(document).delegate(".goods-list-goods-item", "mouseenter", function () {
        $(this).find("img").eq(0).hide()
        $(this).find("img").eq(1).show()
        $(this).find(".goods-list-shoes-size").toggle();
        return
        let largeSrc = $(this).find("img").eq(0).toggle() //.data("largeSrc");
        // console.log(largeSrc)
        $(this).find("img").attr("src", largeSrc);
      })


      $(document).delegate(".goods-list-goods-item", "mouseleave", function () {
        $(this).find("img").eq(1).hide()
        $(this).find("img").eq(0).show()
        $(this).find(".goods-list-shoes-size").toggle();
        return
        let src = $(this).find("img").data("src")
        $(this).find("img").attr("src", src);
      })
      // 筛选,单个清除
      $(document).delegate(".goods-list-close-other", "click", function () {
        $(this).parent(".goods-list-filter-top-item-other").remove();
        var value = $(this).data("value")
        var filter = $(this).data("typename")
        var index = $(this).data("itemindex")
        var arrindex = $(this).data("index");
        // 同时清除存储的数据
        removeDataCss(filter, index, arrindex);
        removeDataFilter(filter, value, arrindex)
        // 调取ajax
      })
      // 清除所有(文字)
      $(".goods-list-clear-label").click(function () {
        $(".goods-list-filter-top-item-other").remove();
        removeAllDataCss()
        // removeAllData();
      })
      // 清除所有(x)
      $(".goods-list-close-all").click(function () {
        $(".goods-list-filter-top-item-other").remove();
        removeAllDataCss();
        // removeAllData();
      })
      // 尺码
      $(document).delegate(".goods-list-size-item", "click", function () {
        $(this).addClass("goods-list-size-current")
        // $(this).siblings().removeClass("goods-list-size-current")
        let filter = $(this).data("filter");
        let index = $(this).index();
        let value = $(this).data("sizeValue");
        let txt = $(this).html();
        addFilter(filter, value, txt, index,$(this));
        // 同时清除存储的数据
        // 调取ajax
      })
      //  性别,单选
      var sexIndex = GetQueryString("gsex")
        $(".goods-list-left-checkbox-item").eq(sexIndex).find(".fake-checkbox").addClass("check-selected")
      // $(document).delegate(".goods-list-left-select-classifyValue .goods-list-left-checkbox-item", "click",
      //   function () {
      //     $(this).siblings().find(".fake-checkbox").removeClass("check-selected")
      //     $(this).find(".fake-checkbox").addClass("check-selected")
      //     let filter = $(this).data("filter");
      //     let index = $(this).index();
      //     let value = $(this).data("sexValue");
      //     let txt = $(this).find("b").html();
      //     hasSex(filterArr)
      //     addFilter(filter, value, txt, index,$(this));
      //     // 同时清除存储的数据
      //     // 调取ajax
      //   })
      // 灵感
      $(document).delegate(".inspiration .goods-list-left-checkbox-item", "click", function () {
        $(this).find(".fake-checkbox").addClass("check-selected")
        let filter = $(this).data("filter");
        let index = $(this).index();
        let value = $(this).data("insValue");
        let txt = $(this).find("b").html();
        addFilter(filter, value, txt, index,$(this));
        // 同时清除存储的数据
        // 调取ajax
      })
      // 季节
      $(document).delegate(".season .goods-list-left-checkbox-item", "click", function () {
        $(this).find(".fake-checkbox").addClass("check-selected")
        let filter = $(this).data("filter");
        let index = $(this).index();
        let value = $(this).data("seasonValue");
        let txt = $(this).find("b").html();
        addFilter(filter, value, txt, index,$(this));

        // 同时清除存储的数据
        // 调取ajax
      })
      // 类型
      $(document).delegate(".type .goods-list-left-checkbox-item", "click", function () {
        $(this).find(".fake-checkbox").addClass("check-selected")
        let filter = $(this).data("filter");
        let index = $(this).index();
        let value = $(this).data("typeValue");
        let txt = $(this).find("b").html()
        addFilter(filter, value, txt, index,$(this))
        // 同时清除存储的数据
        // 调取ajax
      })
      // 颜色
      $(document).delegate(".goods-list-select-color", "click", function () {
        let filter = $(this).data("filter");
        let index = $(this).index();
        let value = $(this).data("colorValue");
        let txt = $(this).data("color")
        addFilter(filter, value, txt, index,$(this))
      })
      // 排序方式
      $(".goods-list-sortord").click(function () {
        $(this).siblings().toggleClass("hide")
      })
      // 选中排序方式
      $(".choose-drop-ways div").click(function () {
        $(this).parent().toggleClass("hide")
        sort = $(this).data("value")
        $.nowpage = 1, $.limit = 40
        $(".goods-list-shose-size").html(40)
        requestData()
        // lazyloadImg()
      })
      // 选择分页数量
      $(".goods-list-shose-size").click(function () {
        $(this).siblings().toggleClass("hide")
      })
      // 选择了分页数量
      $(".choose-page-size div").click(function () {
        $(this).parent().toggleClass("hide")
        $(".choose-page-size").siblings().html($(this).html())
        // 应该请求后台数据
        $.limit = $(this).html() || 40, $.nowpage = 1
        requestData()
      })

      // 左侧筛选区域展开收起
      $(document).delegate(".goods-list-left-title", "click", function () {
        $(this).siblings().toggle()
      })

    })
    // ===========分割线

    /* 
      点击分类选项,添加到筛选区域
      filter:分类的index,
      value:后台实际请求的值,
      txt:该项的文字(即筛选的文字),
      index:该项的下标
    */
    function addFilter(filter, value, txt, index,that) {
      var obj = {
        filterIndex:filter,
        filter: filters[filter],
        value: value,
        txt: txt,
        index: index
      };

      // console.log(obj)

      // 判断数组里是否添加过该项
      if (filterArr.length) {
        if (removeDuplication(obj, filterArr)) {
          filterArr.unshift(obj)
          renderFilter(filterArr)
        }else{
          // removeCheckedItem(filterIndex=filter,value)
          var checkedIndex = removeCheckedItem(filterIndex=filter,value)
          filterArr.splice(checkedIndex,1)
          renderFilter(filterArr)
          console.log(that,filter);
          
          // 表明已点击过该选项
          switch (filter) {
            case 0:
              that.removeClass("goods-list-size-current")
              break;
            case 1:
                that.find(".check-selected").removeClass("check-selected")
                break;
            default:
                that.find(".check-selected").removeClass("check-selected")
                break;
          }
        }
      } else {
        filterArr.unshift(obj)
        renderFilter(filterArr)
      }
      requestData();      
    }
    /* 
      去除多余的选项的数据
    */
    function removeCheckedItem(filterIndex,value){
      var newArr = JSON.parse(JSON.stringify(filterArr))//.reverse()
      for(var i=0;i<newArr.length;i++){
        if(newArr[i].filterIndex == filterIndex){
          if(newArr[i].value == value){
            return i;
          }
        }
      }
    }

    /* 
      筛选渲染
      arr:array,要渲染的数据
    */
    function renderFilter(arr) {
      // 重新请求数据
      // requestData();
      // 渲染筛选条件
      var str = "";
      arr.forEach(function (e, index) {
        // console.log(e);
        str += `<div class="goods-list-filter-top-item-other">
              <div>${e.filter}:${e.txt}</div>
              <div class="close-filter goods-list-close-other" data-typename="${e.filter}"
               data-itemindex="${e.index}" data-value="${e.value}" data-index="${index}"></div>
            </div>`;
      });
      $(".goods-list-filter-top-box").html(str)
      lazyloadImg();
    }

    /* 
      判断数组里是否添加过该项
      pam:当前选中的数据,
      arr:已经存在的数据
    */
    function removeDuplication(pam, arr) {
      var index = pam.index;
      for (var i = arr.length; i > 0; i--) {
        if (pam.filter == arr[i - 1].filter) {
          if (arr[i - 1].index == index) {
            return false;
          }
        }
      }
      return true;
    }

    /* 
      仅针对性别是否已选,若为是,则直接删掉已有数据里的性别选择数据
    */
    function hasSex(filterArr) {
      if (filterArr.length) {
        for (var i = 0; i < filterArr.length; i++) {
          if (filterArr[i].filter == "性别") {
            filterArr.splice(i, 1)
          }
        }
      }
    }

    /* 
      根据筛选区的x,对底部区域进行样式操作,同时删除掉该筛选项
      filter:string,6大分类
      index:number,该项在所在分类中的下标
      arrindex:number,该项在该筛选数组(例如尺码)中的下标
    */
    function removeDataCss(filter, index, arrindex) {
      // 删掉
      filterArr.splice(arrindex, 1);
      // 重新渲染
      renderFilter(filterArr);

      // 懒加载
      // lazyloadImg()
      // 样式操作
      switch (filter) {
        case "尺码":
          $(".goods-list-size-item").eq(index).removeClass("goods-list-size-current");
          break;
        case "性别":
          $(".goods-list-left-select-classifyValue .goods-list-left-checkbox-item").find(".fake-checkbox").removeClass(
            "check-selected")
          break;
        case "类型":
          $(".type .goods-list-left-checkbox-item").eq(index).find(".fake-checkbox").removeClass("check-selected")
          break;
        case "季节":
          $(".season .goods-list-left-checkbox-item").eq(index).find(".fake-checkbox").removeClass("check-selected")
          break;
        case "颜色":
          break;
        case "灵感":
          $(".inspiration .goods-list-left-checkbox-item").eq(index).find(".fake-checkbox").removeClass(
            "check-selected")
          break;
      }
    }

    /* 
    返回当前值在该数组中的下标
    data:array
    value:string/number
    */
    function nowIndex(data, value) {
      for (var i = 0; i < data.length; i++) {
        if (value == data[i]) {
          return i;
        }
      }
    }


    /* 
    删除一个筛选条件(数据操作)
    filter:string,例如尺码
    value:string/number,即该项的实际值,多为该项的id
    */
    function removeDataFilter(filter, value, arrindex) {
      switch (filter) {
        case filters[0]:
          size.splice(nowIndex(size, value), 1)
          size = arraySingle(size)
          break;
        case filters[1]:
          sex = []
          break;
        case filters[2]:
          type.splice(nowIndex(type, value), 1)
          type = arraySingle(type)
          break;
        case filters[3]:
          season.splice(nowIndex(season, value), 1)
          season = arraySingle(season)
          break;
        case filters[4]:
          color.splice(nowIndex(color, value), 1)
          color = arraySingle(color)
          break;
        case filters[5]:
          inspiration.splice(nowIndex(inspiration, value), 1)
          inspiration = arraySingle(inspiration)
          break;
      }
      // return;
      // 重新请求数据
      requestData();
    }

    /* 
    清除所有数据    
    */
    function removeAllData() {
      gsex = gsex||0
      console.log(gsex)
      location.href = "./goods-list.html?gsex=" + gsex;
      return;
      // 重新加载
      size = [], sex = [], type = [], season = [], color = [], inspiration = [], $.nowPage = 1, $.limit = 40, $
        .goodsList = [];
      requestData();
    }

    /* 
    数组去重
    */
    function arraySingle(e) {
      return Array.from(new Set(e))
    }


    /* 
      清除全部的筛选数据与选中的样式,分页数据也重置,感觉和上面的有点重复,看看(2019年7月7日22:12:43)
    */
    function removeAllDataCss() {
      removeAllData()
      if (filterArr.length == 0) return
      filterArr = [];
      renderFilter(filterArr);
      $(".goods-list-size-item").removeClass("goods-list-size-current");
      $(".goods-list-left-select-classifyValue .goods-list-left-checkbox-item").find(".fake-checkbox").removeClass(
        "check-selected")
      $(".type .goods-list-left-checkbox-item").find(".fake-checkbox").removeClass("check-selected")
      $(".season .goods-list-left-checkbox-item").find(".fake-checkbox").removeClass("check-selected")
      $(".inspiration .goods-list-left-checkbox-item").find(".fake-checkbox").removeClass(
        "check-selected")
    }

    function isShow(e){
      // console.log(e)
      if(e==1){
        $(".goods-list-page-box").hide()
      }else{
        $(".goods-list-page-box").show()
      }
    }

    /* 
      分页
      limit:每页几条数据
      count:总数
    */
    function pageation(limit, count) {
      function newPage(e) {
        $.nowpage = e
        // 不知道行不行
        // requestData()
      }
      layui.use('laypage', function () {
        var laypage = layui.laypage;
        laypage.render({
          elem: $(".page-top"),
          count: count,
          limit: limit,
          prev: " ",
          next: " ",
          curr: $.nowpage,
          groups: 2,
          jump: function (a, b) {
            isShow(a.pages)
            newPage(a.curr)
            if (!b) {
              requestData()
            }
            $(".start-end").html(`${startIndex}-${endIndex}`)
            // console.log(a,b)
          }
        });
      });
    }

    /* 
      渲染商品
    */
    function renderGoodsList(arr) {
      var arr1 = [...arr]
      arr1.length = $.limit || 40;
      $(".goods-list-goods-items-box")
      var str = "";
      arr1.forEach(function (e, index) {
        // console.log(e.id,e.img[0])
        var strs = "";
        e.size_id.forEach(function (size) {
          strs += `<span>${size}</span>`
        })
        
        str += `<a href="./goods-details.html?id=${e.id}&gsex=${gsex||''}&classifyValue=1">
            <div class="goods-list-goods-item">
              <div class="good-list-img-p">
                <img data-original="${HOST+(e.img[0]?e.img[0]:''||"")}" class="lazy goods-list-goodsimg">
              <img src="${HOST+(e.img[1]?e.img[1]:''||"")}" style="display:none" class="goods-list-goodsimg">
              </div>
              <!--<div class="goods-list-shoes-size" style="display: none">
                ${strs}
              </div>-->
              <div class="goods-list-goodsname">${e.good_name||""}</div>
              <div class="goods-list-goodstype">${e.version||""}</div>
              <div class="goods-list-shadow"></div>
            </div>
          </a>`
      })
      $(".goods-list-goods-items-box").html(str)
      pageArea()
      lazyloadImg()
      // console.log(str)
    }
    /* 
    筛选的初始化
    */
    //  尺码
    function filterSizeInit(e) {
      var str = "";
      for (var i = 0; i < e.length; i++) {
        str += `
        <span class="goods-list-size-item" data-size-value="${e[i].id}" data-filter="0">${e[i].size}</span>`
      }
      $(".goods-list-left-content-size").html(str)
    }
    // 性别
    function filterSexInit(e) {
      var str = "";
      for (var i = 0; i < e.length; i++) {
        str += `
        <div data-filter="1" data-sex-value="${e[i].id}" class="goods-list-left-checkbox-item">
                <div class="fake-checkbox"></div>
                <b>${e[i].fit}</b>
              </div>`
      }
      // $(".goods-list-left-select-classifyValue").html(str)
    }
    // 类型
    function filterTypeInit(e) {
      var str = "";
      for (var i = 0; i < e.length; i++) {
        str += `
        <div data-filter="2" data-type-value="${e[i].id}" class="sh-space-between goods-list-left-checkbox-item">
                <div class="sh-flex">
                  <div class="fake-checkbox"></div>
                  <b>${e[i].type}</b>
                </div>
                <div class="good-list-surplus-num">(${e[i].count})</div>
              </div>`
      }
      $(".type").html(str)
    }
    // 季节
    function filterSeasonInit(e) {
      var str = "";
      for (var i = 0; i < e.length; i++) {
        str += `
        <div data-filter="3" data-season-value="${e[i].id}" class="sh-space-between goods-list-left-checkbox-item">
                <div class="sh-flex">
                  <div class="fake-checkbox"></div>
                  <b>${e[i].season}</b>
                </div>
                <div class="good-list-surplus-num">(${e[i].count})</div>
              </div>`
      }
      $(".season").html(str)
    }
    // 颜色
    function filterColorInit(e) {
      var str = "";
      for (var i = 0; i < e.length; i++) {
        str += `
        <span data-filter="4" data-color-value="${e[i].id}" class="goods-list-select-color" style="background-image: url(${HOST+e[i].img})!important;background-size: cover;"
        title="${e[i].color}" data-color="${e[i].color}"></span>`
      }
      $(".goods-list-left-color-box").html(str)
    }
    // 灵感
    function filterInspirationInit(e) {
      var str = "";
      for (var i = 0; i < e.length; i++) {
        str += `
        <div data-filter="5" data-ins-value="${e[i].id}" class="sh-space-between goods-list-left-checkbox-item">
                <div class="sh-flex">
                  <div class="fake-checkbox"></div>
                  <b>${e[i].inspiration}</b>
                </div>
                <div class="good-list-surplus-num">(${e[i].count})</div>
              </div>`
      }
      $(".inspiration").html(str)
    }

    /* 
      获取筛选条件数据
    */
    function requestFilter() {
      var data = [];

      $.ajax({
        type: "post",
        url: `${HOST}/index/good/screen`,
        success: (res) => {
          // console.log("筛选", res)
          if (res.success == 1) {
            var d = res.data
            // 尺码
            filterSizeInit(d.size)
            // 性别
            filterSexInit(d.fit)
            // 类型
            filterTypeInit(d.type)
            // 季节
            filterSeasonInit(d.season)
            // 颜色
            filterColorInit(d.color)
            // 灵感
            filterInspirationInit(d.inspiration)
            data.push(d.size)
            data.push(d.fit)
            data.push(d.type)
            data.push(d.season)
            data.push(d.color)
            data.push(d.inspiration)
            // console.log(data)
            if (urlClassify) {
              classifyValueIndex = getClassifyValueIndex(data, urlClassify, urlclassifyValue);
              // console.log("classifyValueIndex---",classifyValueIndex)
              // console.log(classifyValueIndex)
              // 再渲染url中选中的那一条数据
              var txt = ""
              // 添加到筛选头部
              switch (urlClassify) {
                case '1':
                  // txt = data[1][classifyValueIndex].fit
                  break;
                case '2':
                  txt = data[2][classifyValueIndex].type
                  break;
              }

              addFilter(urlClassify, urlclassifyValue, txt, classifyValueIndex);
              urlAddFilterIktemCss(urlClassify, classifyValueIndex)
            } else {
              requestData();
            }
          }
        }
      })
    }

    /* 
      获取url参数中之前页面点击的参数值,例如选的男性,type为1,type值为21
      data:,array,获取到的筛选的参数
      a,type分类
      b,type分类的值
     */
    function getClassifyValueIndex(data, a, b) {
      // console.log(data, a, b)
      var arr = data[a]
      for (var i = 0; i < arr.length; i++) {
        // console.log(arr[i].id)
        if (arr[i].id == b) {
          return i;
        }
      }
    }

    function pageArea() {
      startIndex = ($.limit * ($.nowpage - 1) + 1),
        endIndex = ($.limit * ($.nowpage)<total?$.limit * ($.nowpage):total)
      $(".start-end").html(`${startIndex}-${endIndex}`)

    }

    function urlAddFilterIktemCss(a, e) {
      // console.log("urlAddFilterIktemCss", e)
      a = parseInt(a)
      var sex = $(".goods-list-filter-other-item-box").eq(1)
      var type = $(".goods-list-filter-other-item-box").eq(2)
      switch (a) {
        case 1:
          sex.find(".fake-checkbox").eq(e).addClass("check-selected")
          break;
        case 2:
          type.find(".fake-checkbox").eq(e).addClass("check-selected")
          break;
        default:
          console.log("a数据类型有问题");
          break;
      }
    }
    /* 
    根据条件筛选数据
    */
    function requestData() {
      size = [], sex = [], type = [], season = [], color = [], inspiration = [];
      if (filterArr.length) {
        filterArr.forEach(function (e) {
          // console.log(e)
          switch (e.filter) {
            case filters[0]:
              size.push(e.value)
              size = arraySingle(size)
              break;
            case filters[1]:
              sex = []
              sex.push(e.value)
              break;
            case filters[2]:
              type.push(e.value)
              type = arraySingle(type)
              break;
            case filters[3]:
              season.push(e.value)
              season = arraySingle(season)
              break;
            case filters[4]:
              color.push(e.value)
              color = arraySingle(color)
              break;
            case filters[5]:
              inspiration.push(e.value)
              inspiration = arraySingle(inspiration)
              break;
            default:
              size = [], sex = [], type = [], season = [], color = [], inspiration = [];
              break;
          }
        })
      }
      $.ajax({
        type: "POST",
        url: `${HOST}/index/good/good`,
        data: {
          color,
          fit: sex,
          inspiration,
          season,
          size,
          type,
          page: $.nowpage,
          limit: $.limit,
          sex: gsex||0,
          good: good || '',
          sort
        },
        success: function (res) {
          if (res.success == 1) {
            var data = res.data;
            total = res.count
            data = manageRegTag(data)
            renderGoodsList(data)
            // console.log(total)
            pageation($.limit, total)
            $(".totalNums").html(total)
          }else{
            var str = `<span style="margin-left:20px;font-size:15px">暂无该产品</span>`
            $(".goods-list-goods-items-box").html(str)
          }
        },
        error: function (e) {
          console.log(e)
        }
      })
    }